package com.efast.dmom.mgmt.controller.master;

import java.util.Map;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.service.master.TmBasPackageSnService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/tmBasPackageSn")
public class TmBasPackageSnController {
	@Autowired
	private TmBasPackageSnService tmBasPackageSnService;

	//创建包装序号
	@RequestMapping(value="createPackageSn")
	public @ResponseBody ResultBean createPackageSn (@RequestBody Map<Object,Object> map) {
		ResultBean result = new ResultBean(true,"'");
		tmBasPackageSnService.createPackageSn((int) map.get("boxQty"),(Integer)map.get("packageId"));
		return result;
	}
	
	//校验box信息并返回
	@RequestMapping(value="getBoxInfo")
	public @ResponseBody ResultBean getBoxInfo(@RequestBody Map<Object,Object> map) {
		ResultBean result = new ResultBean(true,"'");
		Map<String,Object> boxMap = tmBasPackageSnService.getBoxInfo((String)map.get("packageSn"));
		Boolean available = (Boolean) boxMap.get("available");
		Boolean hasSn = (Boolean) boxMap.get("hasSn");
		if(hasSn) {
			if(available) {
				result.setObject(boxMap);
			}else {
				result.setSuccess(false);
				result.setMessage("扫入的箱号已被使用，请检查后重新扫入！");
			}
		}else {
			result.setSuccess(false);
			result.setMessage("扫入的箱号不存在，请校验箱号！");
		}
		return result;
	}
}
